package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsAboutUs;
import com.macro.mall.model.UmsFeedback;
import com.macro.mall.service.AboutUsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台展示关于我们和意见反馈的controller
 * @author 高强
 * @Date 2020年9月4日
 */
@Controller
@RequestMapping("/about")
public class AboutUsController {
    @Autowired
    private AboutUsService aboutUsService;
    /**
     * 新增一条关于我们，同时删除其他的
     * @param aboutUs
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/createAboutUs",method = RequestMethod.POST)
    public CommonResult createAboutUs(@RequestBody UmsAboutUs aboutUs){
        return aboutUsService.createAboutUs(aboutUs);
    }

    /**
     * 获取关于我们
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAboutUs",method = RequestMethod.GET)
    public CommonResult<UmsAboutUs> getAboutUs(){
        return aboutUsService.getAboutUs();
    }

//    /**
//     * 编辑关于我们
//     * @param aboutUs
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping(value = "/updateAboutUs",method = RequestMethod.POST)
//    public CommonResult updateAboutUs(@RequestBody UmsAboutUs aboutUs){
//        return aboutUsService.updateAboutUs(aboutUs);
//    }

    /**
     * 获取意见反馈
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getFeedbackList",method = RequestMethod.GET)
    public CommonResult<CommonPage<UmsFeedback>> getFeedbackList(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(required = false,defaultValue = "5") Integer pageSize){
        List<UmsFeedback> umsFeedbackList =  aboutUsService.getFeedbackList(pageNum,pageSize);

        return CommonResult.success(CommonPage.restPage(umsFeedbackList));
    }

    /**
     * 删除指定意见反馈
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteFeedback/{id}",method = RequestMethod.GET)
    public CommonResult deleteFeedback(@PathVariable(value = "id") Long id){
        int count = aboutUsService.deleteFeedback(id);
        return CommonResult.success(count);
    }

    /**
     * 批量删除反馈意见
     * @param ids
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteFeedbackList",method = RequestMethod.POST)
    public CommonResult deleteFeedbackList(@RequestParam("ids") List<Long> ids){
            int count = aboutUsService.deleteFeedbackList(ids);
            return CommonResult.success(count);
    }

}
